home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994…tember: Reference Library / Dev.CD Sep 94.toast / Periodicals / develop / develop Issue 19 / develop 19 code / GX Bitmaps / EncrustImage.c < prev   
Encoding:
C/C++ Source or Header  |  1994-07-22  |  5.4 KB  |  227 lines  |  [TEXT/KAHL]

  1. /*
  2. ••••••••••••••••••••
  3.     EncrustImage.c
  4.     David Surovell
  5.  
  6.     this file contains 1 routine BitmapShape_Encrust() that demonstrates
  7.     combining 2 shapes via gx transfer mode. The combination is using
  8.     the 1st shape’s hue and saturation with the 2nd shape’s brightness.
  9.  
  10.     This effect is shown in the 3rd color plate on the inside cover of
  11.     Inside Macintosh: GX Objects
  12.  
  13. ••••••••••••••••••••
  14. */
  15.  
  16. #include <Types.h>
  17. #include <Memory.h>
  18. #include <QuickDraw.h>
  19. #include <Windows.h>
  20.  
  21. #include "graphics types.h"
  22. #include "graphics errors.h"
  23. #include "graphics routines.h"
  24. #include "graphics toolbox library.h"
  25. #include "graphics libraries.h"
  26.  
  27. #include "offscreen library.h"
  28.  
  29.  
  30. void BitmapShape_Encrust(
  31.     gxShape    originalShape1,
  32.     gxShape    originalShape2,
  33.     gxShape    bitmapDest );
  34. void SetHueTransferMode(
  35.     gxShape    targetShape );
  36. void SetLuminanceTransferMode(
  37.     gxShape    targetShape );
  38. void Shape_GetTransferMode(
  39.     gxShape            targetShape,
  40.     gxTransferMode    *curXfer );
  41. void Shape_SetTransferMode(
  42.     gxShape            targetShape,
  43.     gxTransferMode    *curXfer );
  44.  
  45.  
  46. void BitmapShape_Encrust(
  47.     gxShape    shape1,
  48.     gxShape    shape2,
  49.     gxShape    bitmapDest )
  50. {
  51. gxTransferMode    savedXferMode;
  52.  
  53.     if ((shape1 == nil) || (shape2 == nil) || (bitmapDest == nil))
  54.         return;
  55.  
  56.     // Copy 1st shape to destination bitmap. 
  57.     CopyToBitmaps( bitmapDest, shape1 );
  58.  
  59.     // Copy 1st shape’s hue data to destination bitmap. 
  60.     Shape_GetTransferMode( shape2, &savedXferMode );
  61.     SetHueTransferMode( shape2 );
  62.     CopyToBitmaps( bitmapDest, shape2 );
  63.     Shape_SetTransferMode( shape2, &savedXferMode );
  64. }
  65.  
  66.  
  67. /*
  68. *    •••NOTE: this won’t work for picture shapes
  69. *    because picture shape inks are ignored!
  70. */
  71. void SetHueTransferMode(
  72.     gxShape    targetShape )
  73. {
  74. gxTransferMode    x;
  75.  
  76.     if (targetShape == nil)
  77.         return;
  78.  
  79.     Shape_GetTransferMode( targetShape, &x );
  80.  
  81.     x.space = gxHSVSpace;
  82.     x.flags = (gxTransferFlag)0;
  83.  
  84.     x.component[0].mode = gxCopyMode;
  85.     x.component[0].flags = 0;
  86.     x.component[0].sourceMinimum = 0x0000;
  87.     x.component[0].sourceMaximum = 0xFFFF;
  88.     x.component[0].deviceMinimum = 0x0000;
  89.     x.component[0].deviceMaximum = 0xFFFF;
  90.     x.component[0].clampMinimum = 0x0000;
  91.     x.component[0].clampMaximum = 0xFFFF;
  92.     x.component[0].operand = 0x0000;
  93.  
  94.     x.component[1].mode = gxCopyMode;
  95.     x.component[1].flags = 0;
  96.     x.component[1].sourceMinimum = 0x0000;
  97.     x.component[1].sourceMaximum = 0xFFFF;
  98.     x.component[1].deviceMinimum = 0x0000;
  99.     x.component[1].deviceMaximum = 0xFFFF;
  100.     x.component[1].clampMinimum = 0x0000;
  101.     x.component[1].clampMaximum = 0xFFFF;
  102.     x.component[1].operand = 0x0000;
  103.  
  104.     x.component[2].mode = gxNoMode;
  105.     x.component[2].flags = 0;
  106.     x.component[2].sourceMinimum = 0x0000;
  107.     x.component[2].sourceMaximum = 0xFFFF;
  108.     x.component[2].deviceMinimum = 0x0000;
  109.     x.component[2].deviceMaximum = 0xFFFF;
  110.     x.component[2].clampMinimum = 0x0000;
  111.     x.component[2].clampMaximum = 0xFFFF;
  112.     x.component[2].operand = 0x0000;
  113.  
  114.     x.component[3].mode = gxNoMode;
  115.     x.component[3].flags = 0;
  116.     x.component[3].sourceMinimum = 0x0000;
  117.     x.component[3].sourceMaximum = 0xFFFF;
  118.     x.component[3].deviceMinimum = 0x0000;
  119.     x.component[3].deviceMaximum = 0xFFFF;
  120.     x.component[3].clampMinimum = 0x0000;
  121.     x.component[3].clampMaximum = 0xFFFF;
  122.     x.component[3].operand = 0x0000;
  123.  
  124.     Shape_SetTransferMode( targetShape, &x );
  125. }
  126.  
  127.  
  128. /*
  129. *    •••NOTE: this won’t work for picture shapes
  130. *    because picture shape inks are ignored!
  131. */
  132. void SetLuminanceTransferMode(
  133.     gxShape    targetShape )
  134. {
  135. gxTransferMode    x;
  136.  
  137.     if (targetShape == nil)
  138.         return;
  139.  
  140.     Shape_GetTransferMode( targetShape, &x );
  141.  
  142.     x.space = gxHSVSpace;
  143.     x.flags = (gxTransferFlag)0;
  144.  
  145.     x.component[0].mode = gxNoMode;
  146.     x.component[0].flags = 0;
  147.     x.component[0].sourceMinimum = 0x0000;
  148.     x.component[0].sourceMaximum = 0xFFFF;
  149.     x.component[0].deviceMinimum = 0x0000;
  150.     x.component[0].deviceMaximum = 0xFFFF;
  151.     x.component[0].clampMinimum = 0x0000;
  152.     x.component[0].clampMaximum = 0xFFFF;
  153.     x.component[0].operand = 0x0000;
  154.  
  155.     x.component[1].mode = gxNoMode;
  156.     x.component[1].flags = 0;
  157.     x.component[1].sourceMinimum = 0x0000;
  158.     x.component[1].sourceMaximum = 0xFFFF;
  159.     x.component[1].deviceMinimum = 0x0000;
  160.     x.component[1].deviceMaximum = 0xFFFF;
  161.     x.component[1].clampMinimum = 0x0000;
  162.     x.component[1].clampMaximum = 0xFFFF;
  163.     x.component[1].operand = 0x0000;
  164.  
  165.     x.component[2].mode = gxCopyMode;
  166.     x.component[2].flags = 0;
  167.     x.component[2].sourceMinimum = 0x0000;
  168.     x.component[2].sourceMaximum = 0xFFFF;
  169.     x.component[2].deviceMinimum = 0x0000;
  170.     x.component[2].deviceMaximum = 0xFFFF;
  171.     x.component[2].clampMinimum = 0x0000;
  172.     x.component[2].clampMaximum = 0xFFFF;
  173.     x.component[2].operand = 0x0000;
  174.  
  175.     x.component[3].mode = gxNoMode;
  176.     x.component[3].flags = 0;
  177.     x.component[3].sourceMinimum = 0x0000;
  178.     x.component[3].sourceMaximum = 0xFFFF;
  179.     x.component[3].deviceMinimum = 0x0000;
  180.     x.component[3].deviceMaximum = 0xFFFF;
  181.     x.component[3].clampMinimum = 0x0000;
  182.     x.component[3].clampMaximum = 0xFFFF;
  183.     x.component[3].operand = 0x0000;
  184.  
  185.     Shape_SetTransferMode( targetShape, &x );
  186. }
  187.  
  188.  
  189. void Shape_GetTransferMode(
  190.     gxShape            targetShape,
  191.     gxTransferMode    *curXfer )
  192. {
  193. gxInk    targetInk;
  194. short    i;
  195.  
  196.     if (curXfer == nil)
  197.         return;
  198.  
  199.     targetInk = nil;
  200.     if (targetShape != nil)
  201.         targetInk = GXGetShapeInk( targetShape );
  202.     if (targetInk != nil)
  203.         (void)GXGetInkTransfer( targetInk, curXfer );
  204.     else
  205.     {
  206.         for (i=0; i<4; i++)
  207.             curXfer->component[i].mode = gxNoMode;
  208.     }
  209. }
  210.  
  211.  
  212. void Shape_SetTransferMode(
  213.     gxShape            targetShape,
  214.     gxTransferMode    *curXfer )
  215. {
  216. gxInk    targetInk;
  217.  
  218.     if ((targetShape == nil) || (curXfer == nil))
  219.         return;
  220.  
  221.     targetInk = GXGetShapeInk( targetShape );
  222.     if (targetInk != nil)
  223.         (void)GXSetInkTransfer( targetInk, curXfer );
  224. }
  225.  
  226.  
  227.